import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../widget/my_image.dart';
class BestList extends StatefulWidget {
  final List<dynamic> bestProduct;

  BestList({this.bestProduct});

  @override
  _BestListState createState() => _BestListState();
}

class _BestListState extends State<BestList> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(left: 20, right: 20),
      child:    ListView.builder(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        scrollDirection: Axis.vertical,
        itemCount: widget.bestProduct.length,
        reverse: true,
        itemBuilder: (context, index) {
          return Column(
            children: [
              InkWell(
                onTap: () {
                  print(widget.bestProduct[index]['productId']);
                  Navigator.of(context).pushNamed('/productContent',
                      arguments: {
                        'productId': widget.bestProduct[index]['productId']
                      });
                },
                child: Container(
                  child: Row(
                    children: <Widget>[
                      Container(
                          width: 200.w,
                          height: 250.w,
                          child: ClipRRect(
                            borderRadius: BorderRadius.circular(5),
                            child: MyImage(imgSrc:widget.bestProduct[index]['image']),
                          ),
                      ),
                      Container(
                        width: 450.w,
                        height: 250.w,
                        padding: EdgeInsets.only(left: 15),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Text(
                              '${widget.bestProduct[index]['productName']}',
                              overflow: TextOverflow.ellipsis,
                              maxLines: 1,
                              style: TextStyle(
                                  color: Colors.black87, fontSize: 15),
                            ),
                            Text('${widget.bestProduct[index]['price']}',
                                style: TextStyle(
                                    color: Colors.red, fontSize: 18)),
                            Row(
                              mainAxisAlignment:
                              MainAxisAlignment.spaceBetween,
                              children: <Widget>[
                                Row(
                                  children: <Widget>[
                                    Text(
                                      '${widget.bestProduct[index]['otPrice']}',
                                      style: TextStyle(
                                        decoration:
                                        TextDecoration.lineThrough,
                                        color: Colors.grey,
                                      ),
                                    ),
                                    SizedBox(
                                      width: 10.w,
                                    ),
                                    Text(
                                      '已售${widget.bestProduct[index]['sales']}件',
                                      style: TextStyle(
                                          color: Colors.grey, fontSize: 10),
                                    ),
                                  ],
                                ),
                                IconButton(
                                    icon: Icon(
                                        Icons.add_shopping_cart,
                                        size: 40.sp,
                                        color: Colors.red),
                                    onPressed: () {

                                    }),
                              ],
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ),
              Divider()
            ],
          );
        },
      ),
    );
  }
}
